import ajax from './ajax.js';
const list = document.getElementById('list');

init();

function init() {
    getUserList();
}

function getUserList() {
    ajax('get', 'http://127.0.0.1/api/userlist').then(result => {
        if (result.flag) {
            drawTable(result.data);
        }
    })

}

function drawTable(data) {
    list.innerHTML = '';
    const table = document.createElement('table');
    for (let i = 0; i < data.length; i++) {
        const tr = document.createElement('tr');
        for (let item in data[i]) {
            const td = document.createElement('td');
            td.innerText = data[i][item];
            tr.appendChild(td);
        }
        table.appendChild(tr);
    }
    list.appendChild(table);
}